package com.ywh.hilttest.test3

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import com.ywh.hilttest.test3.dynamic_param.SdkConstructorObject2
import com.ywh.hilttest.test3.dynamic_param.SdkConstructorObject2Factory
import com.ywh.hilttest.test3.static_param.SdkConstructorObject
import com.ywh.hilttest.test5.SingletonGlobal
import com.ywh.hilttest.test5.SingletonSdkGlobal
import com.ywh.hilttest.test6.SingletonActivity
import com.ywh.hilttest.test6.SingletonSdkActivity
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import javax.inject.Named

@AndroidEntryPoint
class FragmentObjectName : Fragment() {
    //一个对象有多个构造函数，用@Named区分哪个函数
    @Named("one")
    @Inject
    lateinit var sdkConstructorObject_1: SdkConstructorObject

    @Named("two")
    @Inject
    lateinit var sdkConstructorObject_2: SdkConstructorObject

    //一个对象有多个构造函数，通过工厂来创建
    @Inject
    lateinit var sdkConstructorObjectFactory: SdkConstructorObject2Factory





    //全局单例
    @Inject
    lateinit var singletonGlobal: SingletonGlobal

    @Inject
    lateinit var singletonSdkGlobal: SingletonSdkGlobal

    //同一Activity单例
    @Inject
    lateinit var singletonActivity: SingletonActivity

    @Inject
    lateinit var singletonActivity2: SingletonActivity


    //同一Activity单例
    @Inject
    lateinit var singletonSdkActivity: SingletonSdkActivity

    @Inject
    lateinit var singletonSdkActivity2: SingletonSdkActivity
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        sdkConstructorObject_1.get()
        sdkConstructorObject_2.get()

        val sdkConstructorObject2_1: SdkConstructorObject2 =
            sdkConstructorObjectFactory.createObject("ywh", 30, "武汉")
        sdkConstructorObject2_1.logParam()

        val sdkConstructorObject2_2: SdkConstructorObject2 =
            sdkConstructorObjectFactory.createObject("ywh", 30)
        sdkConstructorObject2_2.logParam()

        Log.e("HiltTest", "SingletonGlobal-hashCode in ${this::class.java.simpleName}:${singletonGlobal.hashCode()}")
        Log.e("HiltTest", "SingletonSdkGlobal-hashCode in ${this::class.java.simpleName}:${singletonSdkGlobal.hashCode()}")
        Log.e("HiltTest", "SingletonActivity-hashCode in ${this::class.java.simpleName}:${singletonActivity.hashCode()},${singletonActivity2.hashCode()}")
        Log.e("HiltTest", "SingletonSdkActivity-hashCode in ${this::class.java.simpleName}:${singletonSdkActivity.hashCode()},${singletonSdkActivity2.hashCode()}")

    }
}